
package com.totoBD.gui.main;

import com.totoBD.gui.swing.components.dialog.DlgConUserCreate;
import com.totoBD.gui.swing.components.dialog.DlgConDbCreate;
import com.totoBD.gui.swing.components.dialog.DlgConDbDrop;
import com.totoBD.gui.swing.components.dialog.DlgConLoginAsRoot;
import com.totoBD.gui.swing.components.dialog.DlgConTableCreate;
import com.totoBD.gui.swing.components.dialog.DlgConUserDrop;
import com.totoBD.gui.swing.components.menubar.MnbtotoBD;
import com.totoBD.gui.swing.components.menuitem.MitBaseCreate;
import com.totoBD.gui.swing.components.menuitem.MitUserCreate;
import com.totoBD.gui.swing.components.menuitem.MitBaseDrop;
import com.totoBD.gui.swing.components.menuitem.MitUserDrop;
import com.totoBD.gui.swing.components.menuitem.MitFileExit;
import com.totoBD.gui.swing.components.menuitem.MitLoginLogout;
import com.totoBD.gui.swing.components.menuitem.MitLoginRoot;
import com.totoBD.gui.swing.components.menuitem.MitTableCreate;
import com.totoBD.jdbc.DbConnectionSingleton;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextPane;
import javax.swing.WindowConstants;

public class TotoBD extends JFrame implements ActionListener{
    /**
     * Creates new form ContactEditor
     */
    public TotoBD() throws Exception {
        initComponents();
    }

    private void initComponents() throws Exception {
        //tmkGuiShrBtnGrpCommand = new TmkGuiShrBtnGrpCommand();
        jTabbedPane = new JTabbedPane();
        jPanel2 = new JPanel();
        jPanel1 = new JPanel();
        jMenuBar1 = new MnbtotoBD((ActionListener)this);
        jTextPane1 = new JTextPane();
        jScrollPane1 = new javax.swing.JScrollPane();

        this.jTextPane1.setEnabled(false);

        Dimension dim = new Dimension (700,500);
        this.setMinimumSize(dim);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setTitle("totoBD");

        this.setJMenuBar(jMenuBar1);

        jTabbedPane.addTab("Client Manager", jPanel1);
        jTabbedPane.addTab("tab2", jPanel2);

        this._dbConnection_ = DbConnectionSingleton.getSingletonObject();
        
        String strUser =_dbConnection_.getUser();

        this.jTextPane1.setText(strUser);


        jScrollPane1.setViewportView(jTextPane1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);

            layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTabbedPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE))
                .addContainerGap())
        );


                layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );


        pack();
    }
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new TotoBD().setVisible(true);
                } catch (Exception ex) {
                    ex.printStackTrace();
                    Logger.getLogger(TotoBD.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    private void _logout_() throws Exception {
        DbConnectionSingleton obj =DbConnectionSingleton.getSingletonObject();
        obj.disconnect();
        this.jTextPane1.setText(obj.getUser());
    }

       public void actionPerformed(ActionEvent e) {

       try{
            if (e.getSource() instanceof MitUserCreate ){
                DlgConUserCreate dlg = new DlgConUserCreate(this, false);
            }
            if (e.getSource() instanceof MitUserDrop){
               DlgConUserDrop dlg = new DlgConUserDrop(this, false);
            }
            if (e.getSource() instanceof MitBaseCreate){
               DlgConDbCreate dlg = new DlgConDbCreate(this, false);
            }
            if (e.getSource() instanceof MitBaseDrop){
               DlgConDbDrop dlg = new DlgConDbDrop(this, false);
            }
            if (e.getSource() instanceof MitLoginRoot){
               DlgConLoginAsRoot dlg = new DlgConLoginAsRoot(this, false);
               this.jTextPane1.setText(dlg.getUser());
            }
            if (e.getSource() instanceof MitLoginLogout){
                _logout_();
            }
            if (e.getSource() instanceof MitFileExit){
                this.dispose();
            }
            if (e.getSource() instanceof MitTableCreate){
               JDialog dlg = new DlgConTableCreate(this, false);
            }


        }

       catch (Exception ex)
       {
           ex.printStackTrace();
       }


    }

    
    private JPanel jPanel1;
    private JPanel jPanel2;
    private JTabbedPane jTabbedPane;
    private JMenuBar jMenuBar1;
    private JTextPane jTextPane1;
    private javax.swing.JScrollPane jScrollPane1;
    private DbConnectionSingleton _dbConnection_;




    
}
